package com.chenfan.mcn.model.dto;

import com.alibaba.fastjson.annotation.JSONField;
import com.chenfan.mcn.config.UserVoContextHolder;
import com.chenfan.mcn.model.DocIntentionOrder;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;
import java.util.List;

/**
 * @author wulg
 * @date 2022/10/28
 */
@Data
public class AnchorSchedulingSearchDTO extends AbstractMcnPrivilegeDTO<DocIntentionOrder> {

    private static final long serialVersionUID = -861351606872688525L;

    /**
     * 月份
     */
    @JSONField(format = "yyyy-MM")
    private Date month;

    /**
     * 红人ID
     */
    private Long starId;

    /**
     * 平台ID
     */
    private List<String> platformIdList;

    /**
     * 平台昵称
     */
    private String platNickName;

    /**
     * 发布形式（数据字典Release_form）
     */
    private List<String> publishForms;

    /**
     * 状态
     */
    private List<Integer> statusList;

    /**
     * 当前页
     */
    @SuppressWarnings("AlibabaPojoNoDefaultValue")
    private Long pageNum = 1L;

    /**
     * 每页大小
     */
    @SuppressWarnings("AlibabaPojoNoDefaultValue")
    private Long pageSize = 10L;

    @Override
    protected void extendCustomerPrivilege(StringBuilder sb) {

    }

    @Override
    protected void extendUserPrivilege(StringBuilder sb) {
        sb.append(" AND (");
        if (CollectionUtils.isNotEmpty(this.getUserIds())) {
            sb.append(this.getAlias()).append("owner_id IN (").append(StringUtils.join(this.getUserIds().toArray(), ",")).append(")");
            sb.append(" OR " + this.getAlias()).append("excutor_id IN (").append(StringUtils.join(this.getUserIds().toArray(), ",")).append(")");
            sb.append(" OR " + this.getAlias()).append("create_by IN (").append(StringUtils.join(this.getUserIds().toArray(), ",")).append(")");
            sb.append(" OR " + this.getAlias()).append("star_agent_id IN (").append(StringUtils.join(this.getUserIds().toArray(), ",")).append(")");
        } else {
            sb.append(this.getAlias()).append("owner_id = ").append(UserVoContextHolder.defaultUserId());
            sb.append(" OR " + this.getAlias()).append("excutor_id = ").append(UserVoContextHolder.defaultUserId());
            sb.append(" OR " + this.getAlias()).append("create_by = ").append(UserVoContextHolder.defaultUserId());
            sb.append(" OR " + this.getAlias()).append("star_agent_id = ").append(UserVoContextHolder.defaultUserId());
        }
        sb.append(")");
    }
}
